﻿<div class="span12">
    <div class="span8" id="incidentesHistoriaContext" data-bind="with:IncidentesHistoria">
        <h4>
            Historia Incidentes</h4>
        <div data-bind="if: emptyArray">
            0 Incidentes registrados.</div>
        <ul class="nav nav-tabs nav-stacked" data-bind="foreach: schema">
            <li><a href="#" data-bind="click:  $parent.cargarIncidentes"><span data-bind="text: Id">
            </span>&nbsp;<span data-bind="text: FechaCreacion"></span></a></li>
        </ul>
    </div>
</div>
<script type="text/javascript">
    /// <reference path="../../knockout-2.1.0.js" />
    /// <reference path="../../knockout.mapping-latest.js" />
    /// <reference path="../shared/utils.js" />
    /// <reference path="../../jquery-1.7.2-vsdoc.js" />
    /// <reference path="../../knockout.wrap.js" />
    function IncidentesHistoria(data) {
        var self = this;

        self.Load = function (info) {
            ko.mapping.fromJS(info, {}, this);
        };

        if (data)
            self.Load(data);

        self.emptyArray = ko.dependentObservable(function () {
            return data.schema == null || data.schema.length == 0;
        });

        self.cargarIncidentes = function (incidente) {
            var id = ko.utils.unwrapObservable(incidente.Id);
            historiaIncidenteViewModel.LoadIncidente(id);
        };
    }

    function HistoriaClinicaRegistroViewModel() {
        var self = this;
        self.Load = function (id) {
            $.ajax({
                url: '/Historia/ObtenerIncidentesHistoriaClinica',
                type: "GET",
                data: { idPaciente: id },
                async: false,
                success: function (data) {
                    self.IncidentesHistoria(new IncidentesHistoria(data));

                }
            });

        };
        self.IncidentesHistoria = ko.observable();
    };

    var historiaClinicaRegistroControl = new HistoriaClinicaRegistroViewModel();
    ko.applyBindings(historiaClinicaRegistroControl, document.getElementById("incidentesHistoriaContext"));
</script>
